package com.baizhi.cmfzdemo.service.impl;

import com.baizhi.cmfzdemo.dao.CmfzCounterDao;
import com.baizhi.cmfzdemo.entity.CmfzCounter;
import com.baizhi.cmfzdemo.service.CmfzCounterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by 54433 on 2019/4/7.
 */
@Service
public class CmfzCounterServiceImpl implements CmfzCounterService {
    //封装集合
    @Autowired
    private CmfzCounterDao cmfzCounterDao;

    @Override
    public Map queryAllCmfzCounter(int page, int rows) {
        //获取总数数量
        Map map = new HashMap();
        int count = cmfzCounterDao.getCount();
        int page2 = (page - 1) * rows;
        try {
            List<CmfzCounter> cmfzAudios = cmfzCounterDao.queryAllCmfzCounter(page2, rows);
            map.put("total", count);
            map.put("rows", cmfzAudios);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return map;
    }

    @Override
    public Map deleteCmfzCounter(int[] ids) {
        Map map = new HashMap();
        try {
            cmfzCounterDao.deleteCmfzCounter(ids);
            System.out.println("执行了删除操作**************");
            map.put("delete", true);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("delete", false);
        }
        return map;
    }

    @Override
    public Map addCmfzCounter(CmfzCounter cmfzCounter) {
        Map map = new HashMap();
        try {
            cmfzCounterDao.addCmfzCounter(cmfzCounter);
            map.put("add", true);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
            map.put("add", false);
        }
        return map;
    }

    @Override
    public Map updateCmfzCounter(CmfzCounter cmfzCounter) {
        Map map = new HashMap();
        try {
            cmfzCounterDao.updateCmfzCounter(cmfzCounter);
            map.put("updateOk", true);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            map.put("updateOk", false);
            e.printStackTrace();
        }
        return map;
    }
}
